package com.hevs.samplewebapp.server.entities;

import java.util.Date;

import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;

import org.codehaus.jackson.annotate.JsonIgnore;
import org.codehaus.jackson.annotate.JsonProperty;
import org.codehaus.jackson.map.annotate.JsonDeserialize;
import org.codehaus.jackson.map.annotate.JsonSerialize;

import com.google.appengine.api.datastore.Key;
import com.hevs.samplewebapp.server.json.KeyDeserializer;
import com.hevs.samplewebapp.server.json.KeySerializer;

@PersistenceCapable
/**
 * Internal Message Entity
 * <p>The data model of an internal message to be persisted in the data base application</p>
 *  
 * @author Arnaud Durand
 * @date 23.04.2012
 *
 */
public class InternalMessage {

	@PrimaryKey
	@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
	/**
	 * Primary key of the message
	 */
	private Key key;

	@Persistent
	/**
	 * Email of the message sender
	 */
	private String senderEmail;
	
	@Persistent
	/**
	 * Firstname of the message sender
	 */
	private String senderFirstName;
	
	@Persistent
	/**
	 * Lastname of the message sender
	 */
	private String senderLastName;

	@Persistent
	/**
	 * Header of the message
	 */
	private String header;

	@Persistent
	/**
	 * Content of the message
	 */
	private String content;

	@Persistent
	/**
	 * Timestamp of the message
	 */
	private Date timestamp;

	@Persistent
	/**
	 * Key of the message sender
	 */
	private Key senderUser;

	@Persistent
	/**
	 * Key of the message receiver
	 */
	private Key receiverUser;

	@JsonSerialize(using = KeySerializer.class)
	/**
	 * Getter for the Key
	 * @return
	 * a key serialized for JSON
	 */
	public Key getKey() {
		return key;
	}

	@JsonDeserialize(using = KeyDeserializer.class)
	/**
	 * Setter for the key
	 * @param key
	 * a key Deserialized for JSON
	 */
	public void setKey(Key key) {
		this.key = key;
	}

	/**
	 * Getter for the content of the message
	 * @return
	 * a string that's the content of the message
	 */
	public String getContent() {
		return content;
	}

	/**
	 * Setter for the content of the message
	 * @param content
	 * String to be the content of the message
	 */
	public void setContent(String content) {
		this.content = content;
	}

	@JsonProperty
	/**
	 * Getter for the timestamp of the message
	 * @return
	 * a date of the message
	 */
	public Date getTimestamp() {
		return timestamp;
	}

	@JsonIgnore
	/**
	 * Setter for the timestamp
	 * @param timestamp
	 * the server date of the message
	 */
	public void setTimestamp(Date timestamp) {
		this.timestamp = timestamp;
	}

	/**
	 * Getter for the header
	 * @return header
	 * the header in string
	 */
	public String getHeader() {
		return header;
	}

	/**
	 * Setter for the header
	 * @param header
	 * the header to set
	 */
	public void setHeader(String header) {
		this.header = header;
	}

	/**
	 * Getter for the senderEmail
	 * @return
	 * String of the sender email
	 */
	public String getSenderEmail() {
		return senderEmail;
	}

	/**
	 * Setter of the senderEmail
	 * @param senderEmail
	 * the Email of the sender of the message to set
	 */
	public void setSenderEmail(String senderEmail) {
		this.senderEmail = senderEmail;
	}

	/**
	 * Getter fot the senderFirstName
	 * @return
	 * String of the sender's firstname
	 */
	public String getSenderFirstName() {
		return senderFirstName;
	}

	/**
	 * Setter for the senderFirstName
	 * @param senderFirstName
	 * the firstname of the message's sender to set
	 */
	public void setSenderFirstName(String senderFirstName) {
		this.senderFirstName = senderFirstName;
	}

	/**
	 * Getter for the senderLastName
	 * @return
	 * String of the sender's lastname
	 */
	public String getSenderLastName() {
		return senderLastName;
	}

	/**
	 * Setter for senderLastName
	 * @param senderLastName
	 * the lastname of the message's sender to set
	 */
	public void setSenderLastName(String senderLastName) {
		this.senderLastName = senderLastName;
	}

	/**
	 * Getter for senderUser
	 * @return senderUser
	 * the key of the message's sender
	 */
	@JsonIgnore
	public Key getSenderUser() {
		return senderUser;
	}

	/**
	 * Setter for senderUser
	 * @param senderUser
	 * the key of the message's sender to set
	 */
	@JsonIgnore
	public void setSenderUser(Key senderUser) {
		this.senderUser = senderUser;
	}

	/**
	 * getter for the receiverUser
	 * @return receiverUser
	 * the Key of the message's receiver
	 */
	@JsonIgnore
	public Key getReceiverUser() {
		return receiverUser;
	}

	/**
	 * Setter for receiverUser
	 * @param receiverUser
	 * The key of the message's receiver to set
	 */
	@JsonIgnore
	public void setReceiverUser(Key receiverUser) {
		this.receiverUser = receiverUser;
	}

}
